﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MKMessageReply", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(MKMessageReply))]
    public class MKMessageReplySerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMKMessageReply clazz;
        
        public MKMessageReplySerializer(IMKMessageReply clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ReceiptDate");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.ReceiptDate))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ConsolidatedData");
            if (clazz.ConsolidatedData!=null) {
                global::Xtee.Core.SerializationMetadata metaConsolidatedData = this.GetMetaData(clazz.ConsolidatedData);
                Writer.WriteTypeAttribute(metaConsolidatedData.TypeQualifiedName.Namespace, metaConsolidatedData.TypeQualifiedName.Name);
                metaConsolidatedData.NewSerializer(clazz.ConsolidatedData).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ConsolidatedData");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("MattersResponses");
            if (clazz.MattersResponses!=null) {
                global::Xtee.Core.SerializationMetadata metaMattersResponses = this.GetMetaData(clazz.MattersResponses);
                Writer.WriteTypeAttribute(metaMattersResponses.TypeQualifiedName.Namespace, metaMattersResponses.TypeQualifiedName.Name);
                metaMattersResponses.NewSerializer(clazz.MattersResponses).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MattersResponses");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ReceiptDate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMessageReply>ReceiptDate");
                }
                clazz.ReceiptDate = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("ReceiptDate")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMessageReply>ReceiptDate", Reader.LocalName);
            }
            if (Reader.LocalName=="ConsolidatedData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMessageReply>ConsolidatedData");
                }
                global::Xtee.Core.SerializationMetadata metaConsolidatedData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IConsolidatedData>(Reader, "ConsolidatedData", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.ConsolidatedData = metaConsolidatedData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IConsolidatedData>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ConsolidatedData");
                    metaConsolidatedData.NewSerializer(clazz.ConsolidatedData).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMessageReply>ConsolidatedData", Reader.LocalName);
            }
            if (Reader.LocalName=="MattersResponses") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMessageReply>MattersResponses");
                }
                global::Xtee.Core.SerializationMetadata metaMattersResponses = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponses>(Reader, "MattersResponses", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.MattersResponses = metaMattersResponses.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IMattersResponses>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("MattersResponses");
                    metaMattersResponses.NewSerializer(clazz.MattersResponses).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMessageReply>MattersResponses", Reader.LocalName);
            }
        }
    }
}
